#!/usr/local/bin/perl
package DM;
use strict; use warnings;
use feature qw/say/;

use Encode qw/decode find_encoding/;

use File::Find qw/find/;
use Cwd qw/getcwd/;

my $valid_file;
my ($nfound,$nskip);
my $enc;
my $ignore_dotfile;
my ($dirp,$udir);

sub get_flist
{
    $valid_file     = $_[0];
    $ignore_dotfile = $_[1];
    $enc = find_encoding("UTF-8") unless $enc;
    $dirp="...";
    $nfound=$nskip=0;
    find \&wanted, $_[2];
    return ($nfound,$nskip);
}

sub wanted
{
    return unless -f $_;
    $nfound++;
    my $dirc=getcwd;
    if($dirc ne $dirp){
	$udir=$enc->decode($dirc)."/";
	$dirp=$dirc;
    }
    $nskip++;
    my $f=$enc->decode($_);
    if($ignore_dotfile&&($udir=~/\/\./||$f=~/^\./)){
	print "#WARN:Skip: $udir$f\n";
	return;
    }
    $nskip--;
    &$valid_file($udir.$f);
}

1;
